<template>
  <div class="login">
    <div class="bg">
    </div>
    <Modal class="login-modal" v-model="loginModal" width="360" :closable="false" :mask-closable="false">
      <div>
        <h2 style="margin:10px;color:#abcdef;text-align:center">
          <img :src="require('@/assets/img/logo.png')" alt="" height="50"></h2>
        <Form ref="formValidate" :model="formValidate" :rules="ruleValidate">
          <Form-item prop="notesId">
            <Input v-model="formValidate.notesId" placeholder="请输入notesId"></Input>
          </Form-item>
          <Form-item prop="password">
            <Input v-model="formValidate.password" @keyup.native.enter="handleSubmit('formValidate')" type="password" placeholder="请输入密码"></Input>
          </Form-item>
          <Row>
            <Col span="12">
            <Checkbox-group v-model="formValidate.remember">
              <Checkbox label="记住我"></Checkbox>
            </Checkbox-group>
            </Col>
          </Row>

        </Form>
      </div>
      <div slot="footer">
        <Button type="primary" size="large" long :loading="modal_loading" @click="handleSubmit('formValidate')">登录
        </Button>
        <small style="text-align: center;display:block" class="subText"></small>
      </div>
    </Modal>
  </div>
</template>
<script>
  // import Cookies from 'js-cookie'
  // import axios from 'axios'
  export default {
    name: 'login',
    data () {
      return {
        loginModal: true,
        modal_loading: false,
        formValidate: {
          notesId: '',
          password: ''
        },
        ruleValidate: {
          notesId: [
            {required: true, message: 'notesId不能为空', trigger: 'blur'}
          ],
          password: [
            {required: true, message: '密码错误', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      handleSubmit (formValidate) { // login
        // console.log(this.formValidate.notesId)
        /*
        this.$refs[this.formValidate.notesId].validate((valid) => {
          // console.log(notesId)
          if (valid) {
            this.$Message.success('登录成功!')
            Cookies.set('token', this.formValidate.password)
            this.$router.push({path: '/index', query: {notesId: this.formValidate.notesId}})
          } else {
            this.$Message.error('登录失败!')
          }
        })
        */
/*
        axios.post('http://192.168.43.228:8388/quickLoan/doLogin', "notesId='999999'&password='11111'")
          .then((res) => {
            console.log(this.formValidate.notesId)
            console.log(this.formValidate.password)
            console.log(res.data.resultCode)
            if (res.resultCode === '10001') {
              this.$router.push({path: '/index', params: {role: res.role}})
            }
          })
*/
        this.$api.login(this.formValidate).then((res) => {
          console.log(this.formValidate.notesId)
          console.log(this.formValidate.password)
          console.log(res.resultCode)
          if (res.resultCode === 10006) {
            console.log(res)
            sessionStorage.setItem('notesId', res.data.notesId)
            sessionStorage.setItem('managerType', res.data.managerType)
            sessionStorage.setItem('userName', res.data.userName)
            sessionStorage.setItem('department', res.data.department)
            sessionStorage.setItem('costCenter', res.data.costCenter)
            this.$router.push('/index')
          }
        },
        )
      }
    }
  }
</script>
